home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: atol or strtol ?
- Date: 18 Jan 1996 21:28:57 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4dn35p$f28@solutions.solon.com>
- References: <4dbobq$763@jupiter.planet.net> <4dk4sc$dmj@spanky.pls.ov.com> <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <ALUN.CHAMPION.96Jan18103414@g7240065.bridge.bst.bls.com>,
- Alun Champion <Alun.Champion@bridge.bst.bls.com> wrote:
- > for (;;) {
- > num = strtol(ptr, &p, 0);
- > if (errno && errno != ERANGE) /* We can deal with ERANGE problems. */
-
- Huh?
-
- What gives you the idea this is correct?
-
- It is unclear what the semantics are; ANSI asserts that a function may set
- errno whether or not there was an error, *if* the function does not define
- its usage of errno. However, even if it does, since the standard has not
- seen fit to declare otherwise, we have no guarantee that errno was not
- set, either by strtol, or by some other previous call.
-
- If you set errno to 0 before calling strtol, you are safer, but even then,
- I see no guarantee from the standard that errno cannot be set for reasons
- not mentioned. (If anyone can verify this, or establish that the library
- may *not* set errno without an error, when it documents conditions for
- setting it, please let me know.)
-
- It is almost never correct to check whether or not errno has been set.
- Your current implementation could fail capriciously because some earlier
- call set errno to a value other than ERANGE.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
- C/Unix proto-wizard -- C/Unix questions? Send mail for help. No, really!
- Using trn? Weird new newsgroup problem? I know the fix! Email me!
- The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
-